package com.jiujia.game.sdk.demo;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.jiujia.game.sdk.JGameSdk;
import com.jiujia.game.sdk.base.JGameConfigManager;
import com.jiujia.game.sdk.base.core.callback.JGameSdkCallback;
import com.jiujia.game.sdk.base.core.model.JGameOrderInfo;
import com.jiujia.game.sdk.base.core.model.JGameRoleInfo;
import com.jiujia.game.sdk.base.core.model.JGameSdkPayInfo;
import com.jiujia.game.sdk.base.core.model.JGameSdkUserInfo;
import com.jiujia.game.sdk.base.util.JGameLog;

/**
 * *************************************************
 * Class: MainActivity
 * Author: Jiujia
 * Time: 2025/4/30 17:00
 * Description: 主界面
 * *************************************************
 */
public class MainActivity extends AppCompatActivity {


    private TextView tv_msg;
    private Button btn_login, btn_pay, btn_report;

    @SuppressLint("SetTextI18n")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        JGameSdk.getInstance().init(this,new JGameSdkCallback() {
            @Override
            public void onLoginSuccess(JGameSdkUserInfo mJGameSdkUserInfo) {
                JGameLog.i("登录成功    " + mJGameSdkUserInfo.toString());
            }

            @Override
            public void onLoginFailed(String error) {
                JGameLog.i("登失败    " + error);
            }

            @Override
            public void onPaySuccess(JGameSdkPayInfo mJGameSdkPayInfo) {
                JGameLog.i("支付成功    " + mJGameSdkPayInfo.toString());
            }

            @Override
            public void onPayFailed(String error) {
                JGameLog.i("支付失败    " + error);
            }
        });


        tv_msg = findViewById(R.id.tv_msg);
        tv_msg.setText(
                "app_id : " + JGameConfigManager.getAppId() + "\n" +
                        "app_key : " + JGameConfigManager.getAppKey() + "\n" +
                        "app_package_id : " + JGameConfigManager.getPackageId() + "\n" +
                        "app_version : " + JGameConfigManager.getVersion() + "\n" +
                        "app_debug_mode : " + JGameConfigManager.isDebugMode());
        btn_login = findViewById(R.id.btn_login);
        btn_pay = findViewById(R.id.btn_pay);
        btn_report = findViewById(R.id.btn_report);
        btn_login.setOnClickListener(v -> {
            // 登录
            JGameLog.i("登录");
            JGameSdk.getInstance().login();
        });
        btn_pay.setOnClickListener(v -> {
            // 支付
            JGameLog.i("支付");

            JGameOrderInfo mJGameOrderInfo = new JGameOrderInfo();
            mJGameOrderInfo.setGoodsID("商品ID");
            mJGameOrderInfo.setGoodsName("商品名称");
            mJGameOrderInfo.setCpOrderID("订单号");
            mJGameOrderInfo.setPrice(10000);
            mJGameOrderInfo.setGoodsDesc("商品描述");
            mJGameOrderInfo.setExtrasParams("透传参数 原封不动的通过回调地址返回");
            mJGameOrderInfo.setCallbackUrl("支付回调");

            JGameRoleInfo mJGameRoleInfo = new JGameRoleInfo();
            mJGameRoleInfo.setServerID("1");
            mJGameRoleInfo.setServerName("服务器1");
            mJGameRoleInfo.setGameRoleID("123456");
            mJGameRoleInfo.setGameRoleName("玖珈");
            mJGameRoleInfo.setGameRoleLevel("1");
            mJGameRoleInfo.setRoleCreateTime("1746181127");
            mJGameRoleInfo.setVipLevel("8");
            mJGameRoleInfo.setGameRoleBalance("666");
            mJGameRoleInfo.setGameRolePower("99999");


            JGameSdk.getInstance().pay(mJGameOrderInfo, mJGameRoleInfo);
        });


        btn_report.setOnClickListener(v -> {
            // 汇报
            JGameLog.i("汇报");
            JGameRoleInfo mJGameRoleInfo = new JGameRoleInfo();
            mJGameRoleInfo.setServerID("1");
            mJGameRoleInfo.setServerName("服务器1");
            mJGameRoleInfo.setGameRoleID("123456");
            mJGameRoleInfo.setGameRoleName("玖珈");
            mJGameRoleInfo.setGameRoleLevel("1");
            mJGameRoleInfo.setRoleCreateTime("1746181127");
            mJGameRoleInfo.setVipLevel("8");
            mJGameRoleInfo.setGameRoleBalance("666");
            mJGameRoleInfo.setGameRolePower("99999");
            JGameSdk.getInstance().report(mJGameRoleInfo);
        });
    }
}